﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DomainModel;
using Utils;
using WebUI.Utils;

namespace WebUI.Models
{
    public class IndSavedTalentViewModel: BaseViewModel
    {
        private int _numPerPage = 15;

        public IndSavedTalentViewModel()
            : base()
        { }

        public IndSavedTalentViewModel(int page)
            : base(new { Page = page})
        {

        }

        public string AvatarUrl { get; set; }
        public Login Login { get; set; }
        public Ind Ind { get; set; }

        //public List<Skill> SkillList { get; set; }
        public int PreviousPage { get; set; }
        public int NextPage { get; set; }

        //ind list
        public List<IndLogin> IndLoginList { get; set; }

        protected override void SetVarsWhichDependOnDynamicParams(dynamic dynParams)
        {
            int loginID = Identity.LoginID;
            int page = dynParams.Page;
            
            IndLogin indLogin = DataUtils.GetIndLoginByID(loginID);
            Login = indLogin.Login;
            Ind = indLogin.Ind;
            //SkillList = DataUtils.GetList<Skill>(ConstUtils.SP_GetSkillListByID, new { IndID = Ind.IndID });
            AvatarUrl = ImageUtils.GetAvatarRelativeUrl(AvatarType.IndAvatar, Ind.IndID, AvatarSizeEnum.Avatar_80x80, Ind.AvatarFileExtension);

            IndLoginList = DataUtils.GetSavedTalentAndShotList(loginID, page, _numPerPage);
            foreach (var indLog in IndLoginList)
            {
                indLog.Ind["AvatarUrl"] = ImageUtils.GetAvatarRelativeUrl(AvatarType.IndAvatar, indLog.Ind.IndID, AvatarSizeEnum.Avatar_80x80, indLog.Ind.AvatarFileExtension);

                foreach (var shot in indLog.Ind.ShotList)
                {
                    shot["ShotUrl"] = ImageUtils.GetShotRelativeUrl(indLog.Ind.IndID, shot.ShotID, ShotSizeEnum.Shot_90x60, shot.FileExtension);
                }
            }
            //get next page
            int totalCount = IndLoginList != null && IndLoginList.Count > 0 ? IndLoginList[0].Ind.TotalCount : 0;
            PreviousPage = CommonUtilities.GetPreviousPage(page);
            NextPage = CommonUtilities.GetNextPage(totalCount, page, _numPerPage);
        }
    }
}